using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Terra.Core.Common.Models.Pagination;
using Terra.Data.Entities.Logging;
using Terra.Data.Models.Loggings;
using Terra.Core.Common.Enums.Logging;

namespace Terra.Data.Repository.Logging;

/// <summary>
/// 异常日志仓储接口
/// </summary>
public interface IExceptionLogRepository : IRepository<ExceptionLog, Guid>
{
    /// <summary>
    /// 记录异常日志
    /// </summary>
    /// <param name="log">异常日志实体</param>
    /// <returns>异常日志实体</returns>
    Task<ExceptionLog> LogAsync(ExceptionLog log);

    /// <summary>
    /// 分页查询异常日志
    /// </summary>
    /// <param name="query">查询参数</param>
    /// <returns>分页结果</returns>
    Task<IPagedList<ExceptionLog>> GetPagedListAsync(ExceptionQueryDto query);

    /// <summary>
    /// 获取指定时间范围内的异常统计
    /// </summary>
    /// <param name="startTime">开始时间</param>
    /// <param name="endTime">结束时间</param>
    /// <returns>按严重程度分组的统计结果</returns>
    Task<List<ExceptionStatsDto>> GetExceptionStatsAsync(DateTime? startTime, DateTime? endTime);

    /// <summary>
    /// 清理指定时间之前的异常日志
    /// </summary>
    /// <param name="beforeTime">清理该时间之前的日志</param>
    /// <returns>清理的记录数</returns>
    Task<int> CleanAsync(DateTime beforeTime);

    /// <summary>
    /// 批量删除异常日志
    /// </summary>
    /// <param name="ids">日志ID列表</param>
    /// <returns>删除的记录数</returns>
    Task<int> BatchDeleteAsync(IEnumerable<Guid> ids);

    /// <summary>
    /// 导出异常日志
    /// </summary>
    /// <param name="query">查询参数</param>
    /// <returns>异常日志列表</returns>
    Task<List<ExceptionLog>> ExportAsync(ExceptionQueryDto query);

    /// <summary>
    /// 获取前端统计数据
    /// </summary>
    /// <param name="startTime">开始时间</param>
    /// <param name="endTime">结束时间</param>
    /// <returns>按日期分组的异常统计</returns>
    Task<List<ExceptionStatsFrontendDto>> GetFrontendStatsAsync(DateTime? startTime, DateTime? endTime);
}
